package com.moon.back.config;

import com.moon.back.entity.User;
import com.moon.back.entity.file.FileNode;
import com.moon.back.util.CaffeineUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * caffine 缓存的优化
 */
@Configuration
public class CaffineConfig {
    @Bean
    public CaffeineUtil<String, User> userCache() {
        return new CaffeineUtil.Builder<String, User>()
                .maximumSize(1000)
                .expireAfterWrite(30, TimeUnit.MINUTES)
                .build();
    }

    @Bean
    public CaffeineUtil<String, FileNode> productCache() {
        return new CaffeineUtil.Builder<String, FileNode>()
                .maximumSize(5000)
                .expireAfterAccess(1, TimeUnit.HOURS)
                .build();
    }
}
